<template>
	<div class="systemUserSetting">
		<el-table :data="roleAllData" fit="true" style="width: 100%">
			<el-table-column type="expand">
				<template slot-scope="scope">
					<el-table :data="scope.row.auths" border style="width: 100%">
						<el-table-column prop="module_name" label="模块名称">
						</el-table-column>
						<el-table-column prop="des" label="描述">
						</el-table-column>
						<el-table-column label="操作">
							<template slot-scope="props">
								<el-button type="primary" @click="showAuth(scope,props)" size="mini">修改权限</el-button>
							</template>
						</el-table-column>
					</el-table>
				</template>
			</el-table-column>
			<el-table-column prop="role_name" label="业务角色"></el-table-column>
		</el-table>

		<el-dialog title="请选择要修改的权限" :visible.sync="auth.visible" width="30%" :before-close="handleClose">
			<span>
		  	业务权限：<el-select clearable v-model="checkRole.jurisdictionVal"  placeholder="请选择业务权限">
				    <el-option v-for="item in checkRole.jurisdiction"  :label="item.desc" :value="item.role">{{item.desc}}</el-option>
				</el-select>
		  </span>
			<span slot="footer" class="dialog-footer">
		    <el-button @click="auth.visible = false">取 消</el-button>
		    <el-button type="primary" @click="addData()">确 定</el-button>
		  </span>
		</el-dialog>

	</div>
</template>

<script>
	import { authGetAll, Login, authUpdate } from '@/assets/util/api.js'
	export default {
		data() {
			return {
				access_token: "",
				auth: {
					scope: "",
					props: "",
					visible: false,
				},
				authVisible: "",
				checkRole: {
					jurisdiction: [{
						"role": "B",
						"desc": "可查看"
					},{
						"role": "A",
						"desc": "可查看及编辑"
					}, {
						"role": "C",
						"desc": "可查看及删除"
					}, {
						"role": "E",
						"desc": "禁止"
					}],
					jurisdictionVal: "",
					roleInUser: "",
					roleInUserVal: "",
					modular: "",
					modularVal: "",
				},
				roleAllData: "",
			};
		},
		mounted() {
			var _this = this;
			_this.checkRole.roleInUser = _this.inStorage("get", "inUserRole");
			this.access_token = _this.inStorage("get", "access_token")
			this.authGetAll();
		},
		methods: {
			authGetAll() {
				var _this = this;
				var params = {
					access_token: this.access_token
				}
				authGetAll(this, params).then((res) => {
					//   		console.log(res);
					if(res.data.state) {
						_this.roleAllData = res.data.data;
					}
				}, (res) => {
					console.log(res);
				})
			},
			showAuth(scope, props) {
				this.auth.visible = true;
				this.auth.scope = scope;
				this.auth.props = props;
			},
			addData() {
				var _this = this;
				console.log(this.auth.props.row)
				if(!this.checkRole.jurisdictionVal){
					this.$message.error("请选择要修改的权限！");
					return;
				}
				var params = {
					access_token: this.access_token,
					module: this.auth.props.row.module,
					auth_level: this.checkRole.jurisdictionVal,
					role: this.auth.scope.row.role,
				}
				authUpdate(this, params).then((res) => {
					console.log(res)
					if(res.data.code) {
						_this.$message.error(_this.publicMsg(res.data.code), res.data.message);
					}
					if(res.data.state) {
						_this.$message.success("修改成功!");
						_this.checkRole.jurisdictionVal = "";
						_this.auth.visible = false;
					}
				}, (res) => {
					console.log(res)
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	.systemUserSetting {
		p span {
			margin-left: 10px;
		}
	}
</style>